/**
 * 
 */
package lt.vin.currency.client.ui;

import java.math.BigDecimal;
import java.util.List;

import lt.vin.currency.client.service.CurrencyService;
import lt.vin.currency.client.service.CurrencyServiceAsync;
import lt.vin.currency.shared.Rate;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Vincentas
 *
 */
public class FrontPageUi extends Composite {
	
	private final CurrencyServiceAsync currencyService = GWT.create(CurrencyService.class);

	private static FrontPageUiBinder uiBinder = GWT.create(FrontPageUiBinder.class);

	interface FrontPageUiBinder extends UiBinder<Widget, FrontPageUi> {
	}

	@UiField
	Button button;
	
	@UiField
	Panel currencies;
	
	@UiField(provided = true)
	SuggestBox currency;

	public FrontPageUi(String firstName) {
		currency = new SuggestBox(new CurrencySuggest(currencyService));
		
		initWidget(uiBinder.createAndBindUi(this));

		// Can access @UiField after calling createAndBindUi
		button.setText(firstName);
	
		Rate rate = new Rate();
		rate.setBuy(new BigDecimal(3.45));
		rate.setSell(new BigDecimal(3.45));
		currencies.add(new CurrencyInfo(rate));
		currencies.add(new CurrencyInfo(rate));
		currencies.add(new CurrencyInfo(rate));	
		
		
	}
	
	@UiHandler("button")
	void onClick(ClickEvent e) {
		Window.alert("Hello!");
	}

}
